Failed Conditions
Push — master ( f5e7b3...711045 )
by Yo
01:30
created

Logger.js ➔ ???   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 10
Bugs 0 Features 0
Metric Value
cc 2
c 10
b 0
f 0
nc 2
nop 4
dl 0
loc 9
rs 9.6666
1
"use strict";
2
3
const wrapWinston = (winstonLogger, level, message, meta) => {
4
    const argList = [];
5
6
    argList.push(message);
7
    if (meta = {}) {
8
        argList.push(meta);
9
    }
10
    winstonLogger[level].apply(winstonLogger, argList);
11
};
12
13
class Logger {
14
    /**
15
     *
16
     * @param {winston.Logger} logger
17
     */
18
    constructor(logger) {
19
        this.logger = logger;
20
    }
21
22
    starting(taskName) {
23
        this.info(`Starting ${taskName} ...`);
24
    }
25
26
    started(taskName) {
27
        this.info(`${taskName} started`);
28
    }
29
30
    /**
31
     * @public
32
     *
33
     * @param {string} message
34
     * @param {Object} meta
35
     */
36
    debug(message, meta = {}) {
37
        this.log('debug', message, meta);
38
    };
39
40
    /**
41
     * @public
42
     *
43
     * @param {string} message
44
     * @param {Object} meta
45
     */
46
    info(message, meta = {}) {
47
        this.log('info', message, meta);
48
    };
49
50
    /**
51
     * @public
52
     *
53
     * @param {string} message
54
     * @param {Object} meta
55
     */
56
    warning(message, meta = {}) {
57
        this.log('warn', message, meta);
58
    };
59
60
    /**
61
     * @public
62
     *
63
     * @param {string} message
64
     * @param {Object} meta
65
     */
66
    error(message, meta = {}) {
67
        this.log('error', message, meta);
68
    };
69
70
    /**
71
     * @protected
72
     * Could be overridden by child class
73
     *
74
     * @param {string} message
75
     * @param {Object} meta
76
     *
77
     * @returns {string}
78
     */
79
    normalizeMessage(message, meta = {}) {
0 ignored issues
show
Unused Code introduced by
The parameter meta is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
80
        return message;
81
    }
82
83
    /**
84
     * @protected
85
     *
86
     * @param {string} level
87
     * @param {string} message
88
     * @param {Object} meta
89
     */
90
    log(level, message, meta = {}) {
91
        return wrapWinston(
92
            this.logger,
93
            level,
94
            this.normalizeMessage(message, meta),
95
            meta
96
        );
97
    }
98
}
99
100
101
module.exports = Logger;
102